package com.itheima.mall.controller.omsController;

import com.itheima.PageResult;
import com.itheima.dto.OmsOrderReturnApplyDto;
import com.itheima.mall.service.omsService.OmsOrderReturnApplyService;
import com.itheima.pojo.oms.OmsOrderReturnApply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {
    @Autowired
    private OmsOrderReturnApplyService omsOrderReturnApplyService;

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity delete(@RequestParam Integer[] ids) {
        omsOrderReturnApplyService.delete(ids);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询退货申请
     *
     * @param dto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult<OmsOrderReturnApply>> list(OmsOrderReturnApplyDto dto,
                                                                Integer pageNum,
                                                                Integer pageSize) {
        PageResult<OmsOrderReturnApply> pageResult = omsOrderReturnApplyService.list(dto, pageNum, pageSize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity findReturnById(@PathVariable Integer id) {
OmsOrderReturnApply omsOrderReturnApply = omsOrderReturnApplyService.findById(id);
        return ResponseEntity.ok(omsOrderReturnApply);

    }


    /**
     * 修改退货申请状态
     *
     * @param id
     * @param omsOrderReturnApply
     * @return
     */
    @PostMapping("update/status/{id}")
    public ResponseEntity updateById(@PathVariable Integer id, @RequestBody OmsOrderReturnApply omsOrderReturnApply) {
        omsOrderReturnApplyService.updateById(id,omsOrderReturnApply);
        return ResponseEntity.ok(null);
    }


}
